package com.taysear.ice;

import com.taysear.dbservice.DbServicesPrx;
import com.taysear.dbservice.DbServicesPrxHelper;

import Ice.Communicator;

/**
 * <code>DbServiceCommunicator</code> is used to create a proxy that is used to communicate true ICE with the DbService module.
 *
 */
public class DbServiceCommunicator {
	
	static String dbServiceProxyString = "DBSERVICE: tcp -h 127.0.0.1 -p 9001";
	static DbServicesPrx dbServicesPrx = null;
	
	/**
	 * This method checks if the Ice Proxy is initialized then if its 
	 * initialized it returns the object otherwise it initializes and returns.
	 */
	public static DbServicesPrx getDbServiceProxy() {
		if(dbServicesPrx != null) {
			return dbServicesPrx;
		} else {
			Communicator iceCommunicator = Ice.Util.initialize();
			
			dbServicesPrx = DbServicesPrxHelper.uncheckedCast(iceCommunicator.stringToProxy(dbServiceProxyString));
			return dbServicesPrx;
		}
	}
}